<?php

use App\Http\Controllers\ClassRoomController;
use App\Http\Controllers\DemoController;
use Illuminate\Support\Facades\Route;

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/

Route::get('/', function () {
    return view('welcome');
});

Route::resource('info', DemoController::class,);


// get 请求路由
Route::get('test', function (){
    echo app()->version();
});
// post 请求路由
Route::post('test2',function (){
    return 456;
});

// match 多请求路由
Route::match(['get', 'post'], 'test3', function (){
    return 789;
});

// any 任意请求路由
Route::any('test4', function (){
    return 101;
});

// 路由参数
//Route::get('user/{id}',function ($id){
//   return 'user-id'. $id;
//});
//
//Route::get('user/{name?}',function ($name = null){
//    return 'user-name'. $name;
//});

// 正则表达式限制
//Route::get('user/{name?}',function ($name = null){
//    return 'user-name'. $name;
//})->where('name','[a-zA-Z]+');

// 多字段
//Route::get('user/{id}/{name?}',function ($id,$name = null){
//    return 'user-id'. $id. 'user-name' . $name;
//})->where(['id' => "[0-9]+",'name' => '[a-zA-Z]+']);

// 路由别名
//Route::get('user/info',['as' => 'info', function (){
//    return route ('info');
//}]);


// 路由群组
Route::group(['prefix' => 'aa'], function(){

    Route::get('user/info',['as' => 'info', function (){
        return route ('info');
    }]);
});

// 路由输出视图
Route::get('view',function (){
   return view('welcome');
});

// 路由绑定控制器方法
Route::get('info1',[
   \App\Http\Controllers\DemoController::class, 'info'
]);

// 路由绑定控制器方法，方法显示路由
Route::get('demo12',[
   \App\Http\Controllers\DemoController::class,'show'
]);

// 方法调用模型
Route::get('call_model',[
   \App\Http\Controllers\DemoController::class,'call_model'
]);


Route::group(['prefix' =>'student'], function (){
    // 获取学生表所有数据
    Route::get('seek_student', [
        \App\Http\Controllers\StudentController::class,'seek_student'
    ]);
    // 添加学生数据
    Route::get('add_student', [
        \App\Http\Controllers\StudentController::class,'add_student'
    ]);
    // 更新学生数据
    Route::get('update_student', [
        \App\Http\Controllers\StudentController::class,'update_student'
    ]);
    // 查找学生
    Route::get('seek_students', [
        \App\Http\Controllers\StudentController::class,'seek_students'
    ]);
    // 删除学生
    Route::get('delete_student', [
        \App\Http\Controllers\StudentController::class,'delete_student'
    ]);
});

// 构造器添加
Route::any('query_add',[
    \App\Http\Controllers\StudentController::class,'query_add'
]);
// 构造器修改
Route::any('query_update',[
    \App\Http\Controllers\StudentController::class,'query_update'
]);
// 构造器删除
Route::any('query_delete',[
    \App\Http\Controllers\StudentController::class,'query_delete'
]);
// 构造器查询
Route::any('query_seek',[
    \App\Http\Controllers\StudentController::class,'query_seek'
]);



// 用户组
Route::group(['prefix' => 'user'],function (){
    // 查找用户
    Route::get('seek_user/{id}',[
       \App\Http\Controllers\UserController::class,'seek_user'
    ]);
    // 添加用户
    Route::get('add_user/{name?}/{age}',[
        \App\Http\Controllers\UserController::class,'add_user'
    ]);
    // 删除用户
    Route::get('del_user/{id?}',[
        \App\Http\Controllers\UserController::class,'del_user'
    ]);
    // 修改用户
    Route::get('update_user/{id?}/{name?}/{age}',[
       \App\Http\Controllers\UserController::class,'update_user'
    ]);
});



Route::get('demo', [
    \App\Http\Controllers\IndexController::class, 'demo'
]);

// 登录分组
Route::group(['prefix' => 'login'], function (){
    // 登录首页
    Route::get('index', [
        \App\Http\Controllers\LoginController::class, 'index'
    ]);
    // 登录
    Route::post('doLogin', [
        \App\Http\Controllers\LoginController::class, 'doLogin'
    ]);
    // 退出登录
    Route::get('logout',[
       \App\Http\Controllers\LoginController::class, 'logout'
    ]);
});

// 管理员首页
Route::group(['middleware' => \App\Http\Middleware\CheckLogin::class, 'prefix' => 'admin'], function (){
    // 主页
    Route::get('index', [
       \App\Http\Controllers\IndexController::class, 'index'
    ]);
    // 管理员列表
    Route::get('admin/index', [
        \App\Http\Controllers\AdminController::class, 'index'
    ]);
    // 显示管理员添加页面
    Route::get('admin/add', [
       \App\Http\Controllers\AdminController::class, 'add'
    ]);
    // 管理员添加
    Route::post('admin/addPost', [
       \App\Http\Controllers\AdminController::class, 'addPost'
    ]);
    // 显示管理员修改页面
    Route::get('admin/edit', [
       \App\Http\Controllers\AdminController::class, 'edit'
    ]);
    // 修改管理员提交
    Route::post('admin/editPost', [
        \App\Http\Controllers\AdminController::class, 'editPost'
    ]);
    // 管理员删除
    Route::get('admin/del', [
        \App\Http\Controllers\AdminController::class, 'del'
    ]);
});


//Route::resource('class', ClassRoomController::class);
